﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Net;
using System.Web;

namespace Tracy.DataModel
{
    public class FeedSource: XmlDataModelWithAliases
    {
        public override string RootNodeName
        {
            get
            {
                return "source";
            }
        }

        public FeedSource(XmlNode node) : base(node) { }
        public FeedSource() : base() { }

        /// <summary>
        /// Name of the feed source
        /// </summary>
        public override string Name
        {
            get { return Attributes["name"]; }
            set { Attributes["name"] = value; }
        }

        /// <summary>
        /// Url of the feed source
        /// </summary>
        public string Url
        {
            get { return Properties["url"]; }
            set { Properties["url"] = value; }
        }

        /// <summary>
        /// Generate URL (The simple way). TODO: Design a general solution later.
        /// This should be used only on the init search, generated keyword part should be cached in entry, for a single entry, different site could use different keywords
        /// </summary>
        /// <param name="entry"></param>
        /// <returns></returns>
        public string GenerateUrl(Entry entry)
        {
            return Url.Replace("{KEYWORDS}", HttpUtility.UrlEncode(entry.SearchKeywords, Encoding.UTF8));
        }

        /// <summary>
        /// Parser of the feed source
        /// </summary>
        public string Parser
        {
            get { return Properties["parser"]; }
            set { Properties["parser"] = value; }
        }

        //TODO: xslt parser
    }
}
